/*
 * timer.c
 *
 * 		Functions for initialising, enabling and disabling timer0
 *
 */

#include <timer.h>

void timer_init(void) {

	/* trigger DMA DAC transfer	*/
	/* clk / 4 = 100MHz / 4 = 25MHz	*/
	/* 25000000Hz / sampleRate	*/
	LPC_TIM0->MR0 = (25000000 / sampleRate);

	/* interrupt on MR0, reset timer on match 0 */
	LPC_TIM0->MCR = 0x0003;

	/* toggle MAT0.0 pin on match */
	LPC_TIM0->EMR = 0x0031;

	/* Reset Timer */
	LPC_TIM0->TCR  = 2;
}

void timer_enable(void) {
	// enable timer
	LPC_TIM0->TCR = 1;
}

void timer_disable(void) {
	// disable timer
	LPC_TIM0->TCR = 0;
}
